<?php

declare (strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Controller\user;

use App\Dao\IntegralDetailDao;
use App\Job\ScanOrderTimeOutJob;
use App\Kernel\Util\UserJwtInstance;
use App\Middleware\User\UserMiddleware;
use App\Request\User\ScanOrder\payRequest;

use App\Request\User\Order\OrderRequest;
use App\Service\User\IntegralDetailService;
use App\Service\User\OrderService;
use App\Service\User\PaymentService;

use App\Service\User\PingPpService;
use App\Service\User\ScanOrderService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Middleware;

/**
 * 扫码订单服务
 *
 * @AutoController()
 * @Middleware(UserMiddleware::class)
 * @author 张昊(2396675557@qq.com)
 * @package App\Controller\user
 */
class ScanOrderController extends Controller
{

    /**
     * @Inject
     * @var ScanOrderService
     */
    private $scan_order_service;

    /**
     * 扫码
     *
     * @param payRequest $request
     * @return mixed
     */
    public function pay(payRequest $request)
    {
        $params = $request->all();

        $params['amount'] = (float)$params['amount'];
        $params['business_id'] = (int)$params['business_id'];
        $params['channel'] = (string)$params['channel'];
        //$params['openid'] = (string)$params['openid'];
        $params['remark'] = isset($params['remark']) ? $params['remark'] : '';

        $result = $this->scan_order_service->pay($params);

        // 异步队列，超时未支付关闭订单
        $this->driver->push(new ScanOrderTimeOutJob($result['order_no']), 30 * 60);

        $this->success($result);

    }
}